<?php namespace Admin\Controller;
use Hdphp\Controller\Controller;

class BrandController extends Controller{
	
	private $BrandModel;
	public function __init(){
		$this->BrandModel=M('\Common\Model\sc_brand');
		if(!isset($_SESSION['info'])){
			go('Login/index');
		}
	}
	
	
	public function index(){
		$BrandData=$this->BrandModel->getBrand();
		if(!$BrandData){
			View::error('没有品牌数据，请添加',U('addBrand'));
		}
		
		View::with('BrandData',$BrandData);
		View::make();
	}
	
	
	//添加品牌
	public function addBrand(){
		if(IS_POST){
			if($this->BrandModel->addBrand()) View::success('添加成功！',U('index'));
			View::error($this->BrandModel->getError());
		}
		
		View::make();
	}
	
	
	//删除品牌
	public function delBrand(){
		
		if($this->BrandModel->delBrand()) View::success('删除成功！');
		View::error('删除失败！');
	}
	
   
    //编辑品牌
    public function editBrand(){
    	if(IS_POST){
    		if($this->BrandModel->editOneBrand()) View::success('修改成功！',U('index'));
			View::error($this->BrandModel->getError());
    	}
		
		//获取旧数据
		$BrandData=$this->BrandModel->getOneBrand();
		View::with('BrandData',$BrandData);
		
		View::make();	
    }
	
	  
	
}
	
	
	
?>